require(["config"], function() {
    require(["jquery", "load"], function($) {
        function Login(){
            this.addListener();
        }
        $.extend(Login.prototype,{
            addListener(){
                $(".btn-login").on("click",this.loginHandler);
            },
            
            loginHandler(){
                //获取表单里的信息
                const data = $(".form-login").serialize();
                console.log(data)
                $.post("http://127.0.0.1/api/login.php", data, (res)=>{
                console.log(res)
                if(res.res_body.status === 1){
                    location = "/";
                } else {
                    $(".login-error").show();
                }
                },"json");

                return false;  
            }
        });
        new Login();
    });
});